package com.pkk.penguin.frame.know.java.driven.jdbc.handle;

import cn.hutool.core.lang.UUID;
import com.pkk.penguin.frame.know.java.driven.jdbc.constant.JdbcConstant.Table;
import javax.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * jdbc的处理操作
 *
 * @author peikunkun
 * @version V1.0
 * @date 2020-10-22 13:13
 **/
@Slf4j
@Service
public class JdbcHandleService {

  @Resource
  private JdbcTemplate jdbcTemplatel;


  /**
   * 保存操作
   *
   * @return boolean
   * @Param isMakeError:是否制作错误
   * @author peikunkun
   * @date 2020/10/22 0022 下午 1:25
   * @since
   */
  @Transactional
  public boolean insert(boolean isMakeError) {
    final String txInsertSQL = new StringBuilder("INSERT INTO ").append(Table.KZ_TX_USER.name())
        .append("(`uname`)  VALUES (?)").toString();
    final int update = jdbcTemplatel.update(txInsertSQL, UUID.randomUUID().toString().substring(0, 6));

    if (isMakeError) {
      int i = 1 / 0;
    }
    return update == 1;
  }


}
